export default {
  setLocal(name: string, data: any) {
    window.localStorage.setItem(name, data)
  },
  getLocal(name: string) {
    return window.localStorage.getItem(name)
  },
  deleteLocal(name: string) {
    window.localStorage.removeItem(name)
  },
  clearLocal() {
    window.localStorage.clear()
  },
  deepClone<T>(data: T): Promise<T> {
    return new Promise((resolve) => {
      const { port1, port2 } = new MessageChannel()
      port1.postMessage(data)
      port2.onmessage = (msg) => {
        resolve(msg.data)
      }
    })
  },
  calculateTotalPages(totalRecords: number, recordsPerPage: number) {
    return Math.ceil(totalRecords / recordsPerPage)
  }
}
